package com.feng.study.demo.product;

import com.google.common.collect.Lists;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ProductV1Service {
    public static void main(String[] args) {
        List<String> list=Lists.newArrayList();
        String s = list.stream().findFirst().orElse("");
        System.out.println(s);
        getProduct2();

//        getProduct();
    }

    public static void getProduct(){
        List<? extends ProductV1> temp= new ArrayList<ProductInfoV1>();
        List<ProductInfoV1> list=Lists.newArrayList(new ProductInfoV1());
        ProductInfoV1 productInfoV1 = new ProductInfoV1();
        ProductInfoV1 productInfoV12 = new ProductInfoV1();
        productInfoV1.setName("娃哈哈");
        productInfoV1.setStoreId("A001");
        productInfoV1.setProductId("0000001");
        list.add(productInfoV1);
        // 不允许添加对象，因为此时编译器只知道temp的类型是List<? extends ProductV1>，要到运行时才知道绑定了new ArrayList<ProductInfoV1>()
        // temp.add(productInfoV1);
        // 只可以初始化的时候赋值
        temp=list;
        System.out.println(temp);

        ProductV1 productV1 = temp.get(1);
        System.out.println(productV1);
        ProductInfoV1 productV11 = (ProductInfoV1) productV1;
        System.out.println(productV11);
        System.out.println(productV11.getProductId());
    }

    public static void getProduct2(){
        List<? super ProductV1> temp=new ArrayList<ProductV1>();
        ProductV1 productV1 = new ProductV1();
        productV1.setProductId("0000002");
        ProductInfoV1 productInfoV1 = new ProductInfoV1();
        productInfoV1.setName("娃哈哈");
        productInfoV1.setStoreId("A001");
        productInfoV1.setProductId("0000001");
        ProductPriceV1 productPriceV1 = new ProductPriceV1();
        productPriceV1.setPrice("99.99");
        productPriceV1.setProductId("0000003");
        temp.add(productV1);
        temp.add(productInfoV1);
        temp.add(productPriceV1);

        ProductV1 object = (ProductV1) temp.get(0);

        ProductV1 object1 = (ProductV1) temp.get(1);
        ProductV1 object2 = (ProductV1) temp.get(2);
        System.out.println(object);
        System.out.println(object1);
        System.out.println(object2);
        System.out.println(temp);
    }
}
